package com.h3c.ptability.config.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenyifan
 * @date 2022/6/19 15:35
 * mq配置类
 */
@Configuration
public class EsignRabbitMqConfig {

    /**
     * 新员工交换机
     */
    public static final String NEM_EXCHANGE_NAME = "nem_exchange";

    /**
     * 新员工交换机
     */
    public static final String HR_SIGN_EXCHANGE_NAME = "hr_sign_exchange";

    //----------------------------------------------------------------------------------------------------
    /**
     * 入职合同签署队列
     */
    public static final String NEM_SIGN_QUEUE_NAME = "nem_sign_queue";

    /**
     * 人才津贴签署队列
     */
    public static final String NEM_SIGN_TALENT_QUEUE_NAME = "nem_sign_talent_queue";

    /**
     * 邮件发送队列
     */
    public static final String NEM_EMAIL_QUEUE_NAME = "nem_email_queue";
    //---------------------------------------------------------------------------------------------------
    /**
     * hr-sign服务获取签署信息队列
     */
    public static final String HR_SIGN_QUEUE_NAME = "hr_sign_queue";

    @Bean("nemExchange")
    public Exchange esSignExchange(){
        return ExchangeBuilder.topicExchange(NEM_EXCHANGE_NAME).durable(true).build();
    }

    @Bean("hrSignExchange")
    public Exchange hrSignExchange(){
        return ExchangeBuilder.topicExchange(HR_SIGN_EXCHANGE_NAME).durable(true).build();
    }


    @Bean("nemSignQueue")
    public Queue nemSignQueue(){
        return QueueBuilder.durable(NEM_SIGN_QUEUE_NAME).build();
    }

    @Bean("nemEmailQueue")
    public Queue nemEmailQueue(){
        return QueueBuilder.durable(NEM_EMAIL_QUEUE_NAME).build();
    }

    @Bean("nemSignTalentQueue")
    public Queue nemSignTalentQueue(){
        return QueueBuilder.durable(NEM_SIGN_TALENT_QUEUE_NAME).build();
    }

    @Bean("hrSignQueue")
    public Queue hrSignQueue(){
        return QueueBuilder.durable(HR_SIGN_QUEUE_NAME).build();
    }



    @Bean
    public Binding nemBindingEsSignExchange(@Qualifier("nemSignQueue") Queue queue,
                                            @Qualifier("nemExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("nem.es.sign").noargs();
    }

    @Bean
    public Binding nemBindingEsEmailExchange(@Qualifier("nemEmailQueue") Queue queue,
                                            @Qualifier("nemExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("nem.email").noargs();
    }

    @Bean
    public Binding nemBindingEsSignTalentExchange(@Qualifier("nemSignTalentQueue") Queue queue,
                                             @Qualifier("nemExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("nem.es.sign.talent").noargs();
    }

    @Bean
    public Binding hrBindingHrSignExchange(@Qualifier("hrSignQueue") Queue queue,
                                                  @Qualifier("hrSignExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("hr.es.sign").noargs();
    }
}
